package com;

import cn.hutool.core.bean.BeanUtil;
import com.atguigu.commonutils.JwtUtil;
import com.atguigu.commonutils.commonOrder.UCenterMemberOrder;
import com.atguigu.msmservice.MsmApplication;
import com.atguigu.msmservice.entity.UcenterMember;
import com.atguigu.msmservice.service.UCenterMemberService;
import com.atguigu.msmservice.util.SMSUtils;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import io.jsonwebtoken.Claims;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;
import java.util.HashMap;

@SpringBootTest(classes = MsmApplication.class)
@RunWith(SpringJUnit4ClassRunner.class)
public class CodeGenerator {

	@Resource
	private UCenterMemberService uCenterMemberService;

	@Test
	public void run(){

		// 1、创建代码生成器
		AutoGenerator mpg = new AutoGenerator();

		// 2、全局配置
		GlobalConfig gc = new GlobalConfig();
		String projectPath = System.getProperty("user.dir");
		System.out.println(projectPath);
		gc.setOutputDir("D:\\java\\guli_arent\\service\\service_msm" + "/src/main/java");
		gc.setAuthor("haoyue1573");
		gc.setOpen(false); //生成后是否打开资源管理器
		gc.setFileOverride(false); //重新生成时文件是否覆盖
		/*
		 * mp生成service层代码，默认接口名称第一个字母有 I
		 * UcenterService
		 * */
		gc.setServiceName("%sService");	//去掉Service接口的首字母I
		gc.setIdType(IdType.ID_WORKER); //主键策略 =>数据库的id字段属性是char
		gc.setDateType(DateType.ONLY_DATE);//定义生成的实体类中日期类型
		gc.setSwagger2(true);// todo 开启Swagger2模式

		mpg.setGlobalConfig(gc);

		// 3、数据源配置
		DataSourceConfig dsc = new DataSourceConfig();
		dsc.setUrl("jdbc:mysql://localhost:3306/guli?serverTimezone=GMT%2B8");
		dsc.setDriverName("com.mysql.cj.jdbc.Driver");
		dsc.setUsername("root");
		dsc.setPassword("123456");
		dsc.setDbType(DbType.MYSQL);
		mpg.setDataSource(dsc);
		// 4、包配置
		PackageConfig pc = new PackageConfig();
		pc.setParent("com.atguigu");
		pc.setModuleName("msmservice"); //模块名
		pc.setController("controller");
		pc.setEntity("entity");
		pc.setService("service");
		pc.setMapper("mapper");
		mpg.setPackageInfo(pc);
		// 5、策略配置
		StrategyConfig strategy = new StrategyConfig();
		//映射数据库中表的名称
		strategy.setInclude("ucenter_member");
		strategy.setNaming(NamingStrategy.underline_to_camel);//数据库表映射到实体的命名策略
		strategy.setTablePrefix(pc.getModuleName() + "_"); //生成实体时去掉表前缀
		strategy.setColumnNaming(NamingStrategy.underline_to_camel);//数据库表字段映射到实体的命名策略
		strategy.setEntityLombokModel(true); // lombok 模型 @Accessors(chain = true) setter链式操作
		strategy.setRestControllerStyle(true); //restful api风格控制器
		strategy.setControllerMappingHyphenStyle(true); //url中驼峰转连字符
		mpg.setStrategy(strategy);
		// 6、执行
		mpg.execute();
	}

	@Test
	public void SendMessage(){
		SMSUtils.sendMessage("浮生若梦","SMS_269500305","18810179282","1236");
		HashMap<String,String> hashMap=new HashMap<>();
		hashMap.put("name","xiaoming");
		String token = hashMap.get("token");
		System.out.println(token);
	}
	@Test
	public void Token(){

		String jwt = JwtUtil.createJWT("1638180112396566530");
		System.out.println(jwt);
		UcenterMember ucenterMember = uCenterMemberService.getById("1638180112396566530");
		//将UCenterMember中的属性拷贝给UCenterMemberOrder
		UCenterMemberOrder uCenterMemberOrder = BeanUtil.copyProperties(ucenterMember, UCenterMemberOrder.class);
		System.out.println(uCenterMemberOrder);

	}

}
